// pages/personalDetails/personalDetails.ts
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
import { updateAddress } from "../../utils/api"
let baseURL = "http://192.168.0.101:3000";
let imageURL = "";
let nick = ""
Page({
  data: {
    userInfo: {},
    address: ""
  },
  onLoad() {
    this.getUserInfo();
  },
  getUserInfo() {
    const that = this;
    wx.getStorage({
      key: "userInfo",
      success(res) {
        that.setData({
          userInfo: res.data,
          address: res.data.userAddress_tb.placeNames
        })
      }
    })
  },
  onSexShow() {
    const that = this;
    wx.chooseLocation(
      {
        success(e: any) {
          updateAddress({
            longitude: e.longitude,
            latitude: e.latitude,
            placeNames: e.address,
          })
          Toast.success("修改成功");
          const arr: any = that.data.userInfo;
          arr.userAddress_tb.latitude = e.latitude;
          arr.userAddress_tb.longitude = e.longitude;
          arr.userAddress_tb.placeNames = e.address;
          wx.setStorage({
            key: "userName",
            data: arr
          })
          that.setData({
            address: e.address
          })
        }
      }
    )
  }
})